package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.PageResult;
import com.woniu.pojo.Coach;
import com.woniu.mapper.CoachMapper;
import com.woniu.service.ICoachService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.vo.CoachSearchVo;
import com.woniu.vo.QueryCoachDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xie
 * @since 2022-10-12
 */
@Service
public class CoachServiceImpl extends ServiceImpl<CoachMapper, Coach> implements ICoachService {

    @Autowired
    private CoachMapper mapper;

    @Override
    public PageResult queryByItemInPage(Coach coach, long currentPage, long pageSize) {
        IPage page=new Page(currentPage,pageSize);
        IPage ipage=mapper.selectByItemInPage(coach,page);
        return new PageResult(ipage.getTotal(),ipage.getRecords());
    }

    @Override
    public QueryCoachDetailVo queryDetailById(String id) {
        QueryCoachDetailVo detail = mapper.selectDetailById(id);
        System.out.println("aaaaaaa"+id+"-------"+detail);
        detail.setRoleName(mapper.selectRoleById(id));
        return detail;
    }

    @Override
    public List<CoachSearchVo> queryName() {
        return mapper.selectName();
    }

    @Override
    public List<Coach> findByGym(String id) {
        QueryWrapper<Coach> wrapper = new QueryWrapper<>();
        wrapper.eq("gym_id",id);
        List<Coach> coachList = mapper.selectList(wrapper);
        return coachList;
    }
}
